/*
 * 创建日期 2004-9-23
 *
 * 更改所生成文件模板为
 * 窗口 > 首选项 > Java > 代码生成 > 代码和注释
 */
package com.ctsi.commons.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectStreamClass;
import java.lang.reflect.Proxy;
/**
 * @author Administrator
 *
 * 更改所生成类型注释的模板为
 * 窗口 > 首选项 > Java > 代码生成 > 代码和注释
 */
public class ObjectInputStream  extends java.io.ObjectInputStream{

	private ClassLoader classloader;

	public ObjectInputStream(InputStream in, ClassLoader loader) throws IOException {
		super(in);
		this.classloader = loader;
	}

	/**
	 * @see java.io.ObjectInputStream#resolveClass(java.io.ObjectStreamClass)
	 */
	protected Class<?> resolveClass(ObjectStreamClass classDesc) throws ClassNotFoundException {
		return ObjectType.loadClass(classDesc.getName(), classloader);
	}

	/**
	 * @see java.io.ObjectInputStream#resolveProxyClass(java.lang.String[])
	 */
	protected Class<?> resolveProxyClass(String[] interfaces) throws ClassNotFoundException {
		Class<?>[] cinterfaces = new Class[interfaces.length];
		for (int i = 0; i < interfaces.length; i++)
			cinterfaces[i] = classloader.loadClass(interfaces[i]);

		try {
			return Proxy.getProxyClass(classloader, cinterfaces);
		} catch (IllegalArgumentException e) {
			throw new ClassNotFoundException(null, e);
		}

	}
}
